﻿@model Etch.OrchardCore.Search.ViewModels.SiteSearchGroupedViewModel

@inject OrchardCore.ContentManagement.Display.IContentItemDisplayManager ContentItemDisplayManager

<section class="section">
    <div class="constrain">
        <form class="form form--centered" method="get">
            <div class="field-group field-group--horizontal">
                <div class="field">
                    <input id="filter" name="filter" type="text" value="@Model.Filter" placeholder="@Model.FilterInputPlaceholder" class="form-control">
                </div>

                <div class="field">
                    <button type="submit" class="btn btn--primary">@Model.SubmitButtonLabel</button>
                </div>
            </div>
        </form>
    </div>
</section>

@if (Model.IsSearching)
{
    <section class="section">
        <div class="constrain">
            <h2>@T["Search Results"]</h2>

            @foreach (var resultGroup in Model.Results)
            {
                <h3>@(string.IsNullOrWhiteSpace(resultGroup.Settings.Heading) ? resultGroup.ContentType : resultGroup.Settings.Heading)</h3>

                @if (resultGroup.HasResults)
                {
                    <ul class="list list--search-results">
                        @foreach (var contentItem in resultGroup.Items)
                        {
                            var contentItemSummary = await ContentItemDisplayManager.BuildDisplayAsync(contentItem, null, Model.ItemsDisplayType);

                            <li class="list__item">
                                @await DisplayAsync(contentItemSummary)
                            </li>
                        }
                    </ul>

                    @if (resultGroup.Settings.HasViewMoreLinkUrl)
                    {
                        <p><a href="@string.Format("{0}/{1}?filter={2}", Context.Request.PathBase, resultGroup.Settings.ViewMoreLinkUrl, Model.Filter)">@resultGroup.Settings.ViewMoreLinkText</a></p>
                    }
                }
                else
                {
                    <p>@(string.IsNullOrWhiteSpace(resultGroup.Settings.EmptyResultsContent) ? Model.EmptyResultsContent : resultGroup.Settings.EmptyResultsContent)</p>
                }
            }
        </div>
    </section>
}